package com.qubuyer.ext

import com.qubuyer.business.auth.view.LoginActivity
import com.qubuyer.core.app.BaseActivity
import com.qubuyer.core.app.BaseFragment
import com.qubuyer.utils.DialogUtil
import com.qubuyer.utils.NavigationUtil
import com.qubuyer.utils.SessionUtil

fun BaseFragment?.checkLogin(block: (() -> Unit)? = null) {
    if (this == null) {
        return
    }
    mContext.checkLogin(block)
}

fun BaseActivity?.checkLogin(block: (() -> Unit)? = null) {
    if (this == null) {
        return
    }
    if (!SessionUtil.getInstance().isLogined) {
        DialogUtil.getConfirmDialog(mContext, "提示", "需要登录后，才能继续以下操作，是否现在登录？", "登录", "取消", false, { _, _ -> NavigationUtil.overlay(mContext, LoginActivity::class.java) }, { dialog, _ -> dialog.dismiss() }).show()
        return
    }
    block?.invoke()
}